package com.leyou.item.web;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.ISpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理请求和响应的方法
 *
 * @version V1.0
 * @package com.leyou.item.web
 * @description:
 * @author: pc
 * @date: 2019/6/26 17:11
 */

@RestController
@RequestMapping("spec")
public class SpecController {

    @Autowired
    private ISpecService specService;

    /**
     * 根据分类id查询规格组及组内规格参数
     */
    @GetMapping("of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsById(@RequestParam("id") Long cid) {
        return ResponseEntity.ok(specService.querySpecsById(cid));
    }


    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(@RequestParam("id") Long cid) {
        List<SpecGroupDTO> result = specService.queryGroupByCategory(cid);
        return ResponseEntity.ok(result);
    }

    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> queryGroupByParam(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching
    ) {
        List<SpecParamDTO> result = specService.queryGroupByParam(gid, cid, searching);

        return ResponseEntity.ok(result);
    }


}
